package homework.mid_autumn_festival.string_exercise;

import jdk.nashorn.internal.runtime.regexp.joni.ast.StringNode;

public class StringDemo {
    public static void main(String[] args) {
        String s1 = "123abc";//字面量创建的字符串对象第一次使用时会缓存在常量池
        String s2 = "123abc";//复用常量池
        String s3 = "123abc";//复用常量池
        System.out.println(s1==s2);//true
        System.out.println(s1==s3);//true

        String s4 = new String("123abc");
        System.out.println(s4==s2);//false 只要new了就会在堆中创建新的对象

        s1 = s1+"!";
        System.out.println(s1==s2);//false 修改内用会创建新的对象

        String s5 = "123";
        String s6 = s5 + "abc";
        System.out.println(s6==s2);//false 这里编译器不作操作,拼接会产生新的对象

        String s7 = "123"+"abc";
        System.out.println(s7==s2);//true 触发预计算特性

        String s8 = "123abc";
        String s9 = new String("123abc");
        System.out.println(s8==s9);//false
        System.out.println(s8.equals(s9));//true




    }
}
